<% layout('/layouts/default.html', {title: '小程序用户', libs: ['dataGrid']}){ %>

<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa fa-list-alt"></i> ${text('小程序用户')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(hasPermi('admin:adminData:view')){ %>
					<a href="${ctx}/ztAdmin/form" class="btn btn-default btnTool" title="${text('新增用户')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
					<a href="#" class="btn btn-default" id="btnDelUser" title="批量充值"><i class="fa fa-filter"></i>批量充值</a>
				    <a href="${ctx}/ztFinancial/listAudit" class="btn btn-default btnTool" title="${text('审核充值')}"><i class="fa fa-filter"></i>审核充值</a>
					<div class="btn-group">
						<a href="javascript:" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
							<i class="fa fa-navicon"></i> <span class="caret"></span>
						</a>
						<ul class="dropdown-menu">
						<!--	<li><a href="javascript:" id="btnExport"><i class="glyphicon glyphicon-export"></i> 导出</a></li>-->
							<li><a href="javascript:" id="btnImport"><i class="glyphicon glyphicon-import"></i>导入用户</a></li>
							<li><a href="javascript:" id="btnImport1"><i class="glyphicon glyphicon-import"></i>导入充值用户</a></li>
						</ul>
					</div>
						<% } %>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${ztAdmin}" action="${ctx}/ztAdmin/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('微信名')}：</label>
					<div class="control-inline">
						<#form:input path="username" maxlength="200" class="form-control width-120"/>
					</div>
				</div>
				 			
				<div class="form-group">
					<label class="control-label">${text('手机号码')}：</label>
					<div class="control-inline">
						<#form:input path="phone" maxlength="18" class="form-control width-120"/>
					</div>
				</div>
			<div class="form-group">
				<label class="control-label">${text('归属公司')}：</label>

				<div class="control-inline width-270">
					<select name='company' style="width:auto;min-width: 90px;padding:6px;border-color:#d2d6de"></select>
				</div>

			</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
	// 初始化第一类型
	initAddress();

	// 更改省份后的操作
	$("select[name='company']").change(function() {
		var provCode = $("select[name='company']").val();
	});


	function initAddress() {

		// ajax请求所有省份
		$.get("${ctx}/ztCompany/listData", {
		}, function(data) {
			$("select[name='company']").empty();

			$("select[name='company']").append("<option value=''>其他用户</option>");
			$.each(data.list, function(i, d) {
				$("select[name='company']").append("<option value='"+d.company+"'>"+ d.companyname +"</option>");
			});

		}, 'json');

	}
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [		
		{header:'${text('微信名')}', name:'username', index:'a.username', width:160, align:"center"},
		
		/* {header:'${text('姓名')}', name:'name', index:'a.name', width:120, align:"center"},
		*/
		{header:'${text('性别')}', name:'sex', index:'a.sex', width:60, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('sys_sex_type')}, val, '${text('女')}', true);
		}}, 
		{header:'${text('头像')}', name:'headimgurl', index:'a.headimgurl', width:80, align:"center",frozen:true, formatter: function(val, obj, row, act){
			return '<img style="width:43px;height:43px;" src="'+val+'"></img>';
		}},
		{header:'${text('手机')}', name:'phone', index:'a.phone', width:90, align:"center"},
		{header:'${text('已使用余额')}', name:'amount', index:'a.amount', width:100, align:"center"},

		{header:'${text('可用余额')}', name:'cashAmount', index:'a.cash_amount', width:90, align:"center"},
		
		
		 {header:'${text('会员类型')}', name:'level', index:'a.level', width:95, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('sys_level_type')}, val, '${text('普通用户')}', true);
		}}, 
				
		
		{header:'${text('最后登录时间')}', name:'endDate', index:'a.end_date', width:210, align:"center"},
		
		
		{header:'${text('商品订单')}', name:'actions', width:95,align:"center", sortable:false, title:false, formatter: function(val, obj, row, act){	
			return '<a href="${ctx}/ztOrder/listself?ztAdmin.id='+row.id+'" class="btnList" title="${text('商品订单')}"><i class="fa fa-navicon"></i></a>';
		}},
		{header:'${text('购物车')}', name:'actions', width:85,align:"center", sortable:false, title:false, formatter: function(val, obj, row, act){	
			return '<a href="${ctx}/ztTrolley/listself?ztAdmin.id='+row.id+'" class="btnList" title="${text('购物车')}"><i class="fa fa-navicon"></i></a>';
		}},
		
		{header:'${text('粉丝')}', name:'actions', width:70,align:"center", sortable:false, title:false, formatter: function(val, obj, row, act){	
			return '<a href="${ctx}/ztFans/list?lastadmin='+row.id+'" class="btnList" title="${text('粉丝')}"><i class="fa fa-navicon"></i></a>';
		}},
		{header:'${text('资金明细')}', name:'actions', width:95,align:"center", sortable:false, title:false, formatter: function(val, obj, row, act){	
			return '<a href="${ctx}/ztFinancial/list?ztAdmin.id='+row.id+'" class="btnList" title="${text('资金明细')}"><i class="fa fa-navicon"></i></a>';
		}},
		/* {header:'${text('提现记录')}', name:'actions', width:95,align:"center", sortable:false, title:false, formatter: function(val, obj, row, act){	
			return '<a href="${ctx}/ztWithdraw/list?ztAdmin.id='+row.id+'" class="btnList" title="${text('提现记录')}"><i class="fa fa-navicon"></i></a>';
		}}, */
		
		
		{header:'${text('操作')}', name:'actions', width:85, align:"center", sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
			<% if(hasPermi('ztGoods:ztGoodsData:edit')){ %>
				
				actions.push('<a href="${ctx}/ztAdmin/form?id='+row.id+'" class="btnList" title="${text('编辑用户')}"><i class="fa fa-pencil"></i></a>&nbsp;');
				
				/*actions.push('<a href="${ctx}/ztAdmin/delete?id='+row.id+'" class="btnList" title="${text('删除用户')}" data-confirm="${text('确认要删除该用户吗？')}"><i class="fa fa-trash-o"></i></a>&nbsp;');*/
					actions.push('<a href="#" class="btnList" title="${text('删除用户')}" data-confirm="${text('禁止删除用户')}"><i class="fa fa-trash-o"></i></a>&nbsp;');
			<% } %>
			return actions.join('');
		}}
	],
	showCheckbox: true,
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
$('#btnImport').click(function(){
	js.layer.open({
		type: 1,
		area: ['400px'],
		title: '导入用户数据',
		resize: false,
		scrollbar: true,
		content: js.template('importTpl'),
		success: function(layero, index){
			layero.find('input[type="checkbox"]').iCheck();
		},
		btn: ['<i class="fa fa-check"></i> 导入',
			'<i class="fa fa-remove"></i> 取消'],
		btn1: function(index, layero){
			var form = {
				inputForm: layero.find('#inputForm'),
				file: layero.find('#file').val()
			};
			if (form.file == '' || (!js.endWith(form.file, '.xls') && !js.endWith(form.file, '.xlsx'))){
				js.showMessage("${text('文件不正确，请选择后缀为 “xls”或“xlsx”的文件。')}", null, 'warning');
				return false;
			}
			js.ajaxSubmitForm(form.inputForm, function(data){
				js.showMessage(data.message);
				if(data.result == Global.TRUE){
					js.layer.closeAll();
				}
				page();
			}, "json");
			return true;
		}
	});
});

	$('#btnImport1').click(function(){
		js.layer.open({
			type: 1,
			area: ['400px'],
			title: '导入用户充值数据',
			resize: false,
			scrollbar: true,
			content: js.template('importTp2'),
			success: function(layero, index){
				layero.find('input[type="checkbox"]').iCheck();
			},
			btn: ['<i class="fa fa-check"></i> 导入',
				'<i class="fa fa-remove"></i> 取消'],
			btn1: function(index, layero){
				var form = {
					inputForm: layero.find('#inputForm2'),
					file: layero.find('#file').val()
				};
				if (form.file == '' || (!js.endWith(form.file, '.xls') && !js.endWith(form.file, '.xlsx'))){
					js.showMessage("${text('文件不正确，请选择后缀为 “xls”或“xlsx”的文件。')}", null, 'warning');
					return false;
				}
				js.ajaxSubmitForm(form.inputForm, function(data){

					if(data.ret==200){
						js.confirm('<div style="overflow:auto;display: block;margin: 0 auto;">当前充值的用户:'+data.number+'人</div>'+
								'<div style="overflow:auto;display: block;margin: 0 auto;">共充值金额：'+data.cashAmountSum+'元</div>', function(){
							js.ajaxSubmit('${ctx}/ztFinancial/topUpTemplate', {
								list : JSON.stringify(data.list)
							}, function(data){
								js.showMessage(data.message);
								js.layer.closeAll();
							});
						});
					}else {
						js.showMessage(data.message);
					}
				}, "json");
				return true;
			}
		});
	});
	$('#btnDelUser').click(function(){
		var userCodes = $('#dataGrid').dataGrid('getSelectRows');
		if (userCodes != null && userCodes.length > 0){
			console.log(userCodes)

				js.layer.open({
					type: 1
					,area: ['400px']
					,title: '提示'
					,content: '<div style="overflow:auto;display: block;margin: 0 auto;">充值金额:<input  type="text" oninput="value=value.replace(/[^\\d]/g,\'\')"  id="cashAmount"  maxlength="9" class="form-control width-120"/></div>'
					,btn: ['确定充值','取消']
					,btnAlign: 'c' //按钮居中
					,shade: 0 //不显示遮罩
					,btn1: function(index, layero){
						var from = {
							userCodes:userCodes,
							cashAmount:layero.find('#cashAmount').val()
						}
						js.ajaxSubmit("${ctx}/ztFinancial/topUp",{str:JSON.stringify(from)}, function(data){
							js.showMessage(data.message);
							if(data.result == Global.TRUE){
								js.layer.closeAll();
								page();
							}

						}, "json");

					}
				});

		}else{
			js.showMessage('请在列表选中要充值的用户');
		}
		return false;
	});
</script>
<script id="importTpl" type="text/template">//<!--
<form id="inputForm" action="${ctx}/ztAdmin/importData" method="post" enctype="multipart/form-data"
	class="form-horizontal mt20 mb10" style="overflow:auto;max-height:200px;">
	<div class="row">
		<div class="col-xs-12 col-xs-offset-1">
			<input type="file" id="file" name="file" class="form-file"/>
			<div class="mt10 pt5">
				<#form:checkbox name="updateSupport" label="${text('否更新已经存在的用户数据')}" class="form-control"
					title="${text('如果用户编码已经存在，更新这条数据。')}"/> &nbsp;
				<a href="${ctx}/ztAdmin/importTemplate" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> ${text('下载模板')}</a>
			</div>
			<font color="red" class="pull-left mt10">
				${text('提示：仅允许导入“xls”或“xlsx”格式文件！')}
			</font>
		</div>
	</div>
</form>
//--></script>
<script id="importTp2" type="text/template">//<!--
<form id="inputForm2" action="${ctx}/ztFinancial/importData" method="post" enctype="multipart/form-data"
	class="form-horizontal mt20 mb10" style="overflow:auto;max-height:200px;">
	<div class="row">
		<div class="col-xs-12 col-xs-offset-1">
			<input type="file" id="file" name="file" class="form-file"/>
			<font color="red" class="pull-left mt10">
				<div class="mt10 pt5">
				<a href="${ctx}/ztFinancial/importTemplate" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> ${text('下载模板')}</a>
			</div>
				${text('提示：仅允许导入“xls”或“xlsx”格式文件！')}
			</font>
		</div>
	</div>
</form>
//--></script>
